<?php

class Ebx_Project_Tools_Iblock extends Ebx_Project_Tools {

	const VAR_PREFIX = 'iblock_vars';

	static function getByCode($code, $type = null) {
		$var = $code.self::VAR_PREFIX;
		if (Ebx_Vars::has($var)) {
			return Ebx_Vars::get($var);
		} elseif (CModule::IncludeModule("iblock")) {
			$filter = array(
				'CODE' => $code,
				'SITE_ID' => SITE_ID
			);

			if (is_string($type)) {
				$filter['TYPE'] = $type;
			}
			$res = CIBlock::GetList(false, $filter);
			if ($iblock = $res->Fetch()) {
				Ebx_Vars::set($var, $iblock);
				return $iblock;
			}
		} else {
			trigger_error('Module iblock is not installed');
		}
	}	

	static function getIdByCode($code, $type = null) {
		$iblock = self::getByCode($code, $type);
		if (null !== $iblock) {
			return (int)$iblock['ID'];
		}
	}

	static function getLinkedFiles($files) {
		
	}

}

?>